import store from '@/store'
import $global from '@/module/tipsGroup'
import Qequest from './request.js'

const loadingHandle = () => {
  const value = store.state.loadingNum
  if (value === 0) {
    $global.$loading()
  }
  store.commit('SET_LOADINGNUM', value + 1)
}
const CallInterface = (url, params, otherParams = {}) => {
  return new Promise((resolve, reject) => {
    loadingHandle()
    Qequest(url, params, otherParams).then(result => {
      resolve(result)
    }).finally(() => {
      store.commit('SET_LOADINGNUM', store.state.loadingNum - 1)
      const value = store.state.loadingNum
      if (value === 0) {
        $global.$hiding()
      }
    })
  })
}
export default CallInterface